//
//  ZDDComposeTextView.swift
//  小蜗牛_新浪微博
//
//  Created by 周冬冬 on 16/7/3.
//  Copyright © 2016年 我的mac. All rights reserved.
//

import UIKit

class ZDDComposeTextView: UITextView {
    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   override var font:UIFont?{
    didSet{
    placeholderLabel.font = font
    }
    }

    var placeholder : String?{
    
        didSet{
        
            placeholderLabel.text = placeholder
        }
    
    }
    
    func setupUI(){
    
        backgroundColor = UIColor.whiteColor()
    
        //添加控件
        addSubview(placeholderLabel)
        //添加约束
        placeholderLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(StautsMargin/2)
            make.top.equalTo(self).offset(8)
            make.width.equalTo(kScreenW - StautsMargin)
        }
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "textViewTextDidChange", name: UITextViewTextDidChangeNotification, object: nil)
        
        
    }
    deinit{
        
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    func textViewTextDidChange(){
    
        placeholderLabel.hidden = self.hasText()
    
    }
     //  MARK: - 懒加载
    private lazy var placeholderLabel:UILabel = {
    
        let lab = UILabel()
        lab.textColor = UIColor.grayColor()
        lab.font = UIFont.systemFontOfSize(12)
        lab.numberOfLines = 0
        return lab
    
    }()
}
